package mx.ipn.presentacion.nomina;



import com.trolltech.qt.gui.QDialog;

import mx.ipn.presentacion.ConexionConNegocios;
import mx.ipn.presentacion.nomina.ui.*;
import mx.ipn.to.*;
import com.trolltech.qt.gui.QTableWidgetItem;
public class BuscarEmp extends QDialog{
	Ui_Buscaremp mod;
	QTableWidgetItem newItem = null;
	QTableWidgetItem itemid = null;
	EmpleadoTO [] arremp;
	public EmpleadoTO emp;
	public BuscarEmp(){
		mod = new Ui_Buscaremp();
		mod.setupUi(this);
		mod.tableWidget.setRowCount(1);
		mod.tableWidget.itemClicked.connect(this,"selectPD()");
		mod.pushButton.clicked.connect(this, "buscar()");
		mod.pushButton_2.clicked.connect(this, "accept()");
        mod.pushButton_3.clicked.connect(this, "reject()");
		//this.show();
	}
    public BuscarEmp(QDialog parent){
		
	}
	public EmpleadoTO  buscaE(int id){
		EmpleadoTO des=null;
		for(int i=0;i<arremp.length;i++)
		{
			if(arremp[i].getIdEmpleado() ==id)
			   des=arremp[i];
		}
		return des;
	}
	public void selectPD(){
		QTableWidgetItem newItem=null;
		int fila = mod.tableWidget.currentRow();
		itemid = mod.tableWidget.item(fila,0);
		emp= buscaE(Integer.parseInt(itemid.text()));
	}
	public void buscar(){
		int k=0;
		try
		{
			String valor = mod.lineEdit.text();
			    if(mod.comboBox.currentText().compareToIgnoreCase("Curp")==0){
			    	if(valor.compareToIgnoreCase("")!=0){
			            arremp = (EmpleadoTO[])ConexionConNegocios.invocaServicio("encontrarEmpleadoActivoPorCURP",valor,EmpleadoTO[].class);
			    	 }
			    }
			    if(mod.comboBox.currentText().compareToIgnoreCase("Todos")==0){
			    arremp = (EmpleadoTO[])ConexionConNegocios.invocaServicio("buscarEmpleadosActivos",EmpleadoTO[].class); 
			    }
				mod.tableWidget.clearContents();
				if(arremp!=null){
					mod.tableWidget.setRowCount(arremp.length);
			       for(int i=0;i<arremp.length;i++)
			        	mod.tableWidget.insertRow(i);
			       for(int j=0;j<arremp.length;j++){
			       	newItem = new QTableWidgetItem(String.valueOf(arremp[j].getIdEmpleado()));
		    	    mod.tableWidget.setItem(k,0,newItem);
		    	    newItem = new QTableWidgetItem(String.valueOf(arremp[j].getPersonaTO().getNombre()));
		    	    mod.tableWidget.setItem(k,1,newItem);
		    	    newItem = new QTableWidgetItem(String.valueOf(arremp[j].getPersonaTO().getCurp()));
		    	    mod.tableWidget.setItem(k,2,newItem);
		    	    newItem = new QTableWidgetItem(String.valueOf(arremp[j].getNss()));
		    	    mod.tableWidget.setItem(k,3,newItem);
		    	    newItem = new QTableWidgetItem(String.valueOf(arremp[j].getPuestoTO().getNombre()));
		    	    mod.tableWidget.setItem(k,4,newItem);
		    	    k++;
			       }
			    }
	    }catch(Exception e){}
	}
}